package iws.g5.uebung1;

import iws.g5.uebung3.Simulator;
import iws.g5.uebung3.StateModel;
import iws.g5.uebung3.enums.OrganicType;
import iws.g5.uebung3.gui.Display;
import iws.g5.uebung3.interfaces.OrganicObject;

public class MatlabDisplay implements Display {
	double[][] matlabField;
	int timeIndex;
	
	public double[][] simulate(int iterations) {
		matlabField = new double[3][iterations];	
		timeIndex = 0;
		Simulator sim = new Simulator(this, 0, iterations);
		sim.simulate();
		return matlabField;
	}
	
	@Override
	public void drawEnvironment(StateModel env) {
		matlabField[0][timeIndex] = 0;
		matlabField[1][timeIndex] = 0;
		matlabField[2][timeIndex] = 0;
		for(int y=0;y<env.getYDimension();y++){
			for(int x=0;x<env.getXDimension();x++){
				OrganicObject object=env.getOrganicObject(x, y);
		
				if(object!=null){
					if(object.getType()==OrganicType.CELL){
						matlabField[0][timeIndex]++;						
					} else if(object.getType()==OrganicType.FOOD){
						matlabField[1][timeIndex]++;						
					} else if(object.getType()==OrganicType.VIRUS){
						matlabField[2][timeIndex]++;						
					}
				}
			}
		}
		timeIndex++;
	}
}
